import java.util.Timer;
import java.util.TimerTask;

public class Demo6 {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("Hello 3000");

            }
        },3000);
        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("Hello 2000");

            }
        },2000);
        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("Hello 1000");

            }
        },1000);
        //确保上述三个任务结束之后再中止
        Thread.sleep(4000);
        timer.cancel();
    }
}
